package com.dbm.model;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public class OracleFunctionUtil {

	private Logger logger = Logger.getLogger(OracleFunctionUtil.class);

	/**
	 * 获取WMS系统的参数配置信�?
	 * 
	 * @param warehouseId
	 *            仓库ID
	 * @param customerID
	 *            货主ID
	 * @param configName
	 *            参数ID
	 * @return 配置的文本信�?
	 */
	public static String getSysConfiguration(String warehouseId, String customerID, String configName) {

		Connection wmsConn = null;
		CallableStatement cs = null;
		String result = "";

		try {
			wmsConn = ConnPoolFactory.getWMSConnection();
			cs = wmsConn.prepareCall("{? = call getsys_configuration(?,?,'',?,'','C')}");
			cs.registerOutParameter(1, oracle.jdbc.OracleTypes.VARCHAR);
			cs.setString(2, warehouseId);
			cs.setString(3, customerID);
			cs.setString(4, configName);
			cs.execute();
			result = cs.getString(1);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				cs.close();
				wmsConn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return result;
	}

	/**
	 * 获取系统定时器是否开�?
	 * 
	 * @param timerName
	 *            定时器ID，以WMS系统中为�?
	 * @return 'Y' | 'N'
	 */
	public static String getSysTimerActiveFlag(String timerName) {
		Connection wmsConn = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "SELECT ACTIVEFLAG FROM SYS_TIMER WHERE TIMERID = ? AND ROWNUM < 2";
		String activeFlag = "";
		try {
			wmsConn = ConnPoolFactory.getWMSConnection();
			ps = wmsConn.prepareStatement(sql);
			ps.setString(1, timerName);
			rs = ps.executeQuery();
			while (rs.next()) {
				activeFlag = rs.getString(1);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				ps.close();
				wmsConn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return activeFlag;
	}

	public static void main(String[] args) {
		System.out.println(getSysTimerActiveFlag("TOP_EMS_SEND"));
	}

}
